using UnityEngine;
using UnityEditor;

public class VextexCount : MonoBehaviour {

    [MenuItem("Tools/Check Vetex Count &c")]
    public static void CheckVextexCount() {
        int totalVertices = 0;
        int totalTriangles = 0;
        Object[] gameObjects = Selection.GetFiltered(typeof(GameObject), SelectionMode.Deep);
        foreach (GameObject go in gameObjects) {
            Mesh mesh = null;
            // Get the sharedMesh from MeshFilter or SkinnedMeshRenderer.
            MeshFilter meshFilter = go.GetComponent<MeshFilter>();
            if (!meshFilter) {
                SkinnedMeshRenderer skinnedMeshRenderer = go.GetComponent<SkinnedMeshRenderer>();
                if (!skinnedMeshRenderer)
                    continue;
                mesh = skinnedMeshRenderer.sharedMesh;
            } else {
                mesh = meshFilter.sharedMesh;
            }
            if (!mesh)
                continue;
            totalVertices += mesh.vertexCount;
            totalTriangles += mesh.triangles.Length / 3;
            Debug.Log(mesh.name + " has " + mesh.vertexCount + " vertices and " + (mesh.triangles.Length / 3) + " triangles.");
        }
        Debug.Log("Total Vertices: " + totalVertices + ". Total Triangles: " + totalTriangles);
        return;
    }
}
